<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>elseif</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="else.html" title="else" />
    <link rel="next" href="endif.html" title="endif" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">elseif</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="else.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="endif.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="elseif"></a>
      <div class="titlepage"></div>
      <a id="IndexElseif" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">elseif</span>
        </h2>
        <p>elseif — 
      Defines another "if...then" condition when a "if...then" condition is false.
          </p>
      </div>
      <div class="refsect1">
        <a id="idp100711056"></a>
        <h2>Description</h2>
        <p>
      Defines another "if...then" condition when a "if...then" condition is false.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp100715136"></a>
        <h2>Syntax</h2>
        <pre class="synopsis"><span class="command"><strong>elseif</strong></span> xa R xb <span class="command"><strong>then</strong></span></pre>
        <p>
      where <span class="emphasis"><em>label</em></span> is in the same instrument block and is not an expression, and where <span class="emphasis"><em>R</em></span> is one of the Relational operators (<span class="emphasis"><em>&lt;</em></span>, <span class="emphasis"><em>=</em></span>, <span class="emphasis"><em>&lt;=</em></span>, <span class="emphasis"><em>==</em></span>, <span class="emphasis"><em>!=</em></span>) (and <span class="emphasis"><em>=</em></span> for convenience, see also under <a class="link" href="ControlConditional.html" title="Conditional Values"><em class="citetitle">Conditional Values</em></a>).
    </p>
      </div>
      <div class="refsect1">
        <a id="idp100787232"></a>
        <h2>Performance</h2>
        <p>
      <span class="emphasis"><em>elseif</em></span> is used inside of a block of code between the <a class="link" href="if.html" title="if"><em class="citetitle">"if...then"</em></a> and <a class="link" href="endif.html" title="endif"><em class="citetitle">endif</em></a> opcodes. When a "if...then" condition is false, it defines another "if...then" condition to be met. Any number of <span class="emphasis"><em>elseif</em></span> statements are allowed.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp100791392"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the elseif opcode. It uses the file <a class="ulink" href="examples/elseif.csd" target="_top"><em class="citetitle">elseif.csd</em></a>.
            </p>
        <div class="example">
          <a id="idp100793248"></a>
          <p class="title">
            <strong>Example 219. Example of the elseif opcode.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
-odac     <span class="comment">;;;realtime audio out</span>
<span class="comment">;-iadc    ;;;uncomment -iadc if realtime audio input is needed too</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o elseif.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">ksmps</span> <span class="op">=</span> 32
<span class="ohdr">nchnls</span> <span class="op">=</span> 2
<span class="ohdr">0dbfs</span> <span class="op">=</span> 1

<span class="oblock">instr</span> 1

ipch <span class="op">=</span> <span class="opc">cpspch</span>(p4)
ienv <span class="op">=</span> p5


<span class="octrl">if</span> (ienv <span class="op">==</span> 0) then 	
	<span class="comment">;ADSR</span>
	kenv <span class="opc">adsr</span> 0.05, 0.05, .95, .05
<span class="octrl">elseif</span> (ienv <span class="op">==</span> 1) then 
	<span class="comment">;Linear Triangular Envelope</span>
	kenv <span class="opc">linseg</span> 0, p3 <span class="op">*</span> .5, 1, p3 <span class="op">*</span> .5, 0
<span class="octrl">elseif</span> (ienv <span class="op">==</span> 2) then 
	<span class="comment">;Ramp Up</span>
	kenv	<span class="opc">linseg</span> 0, p3 <span class="op">-</span> .01, 1, .01, 0
<span class="octrl">endif</span>

aout	<span class="opc">vco2</span> 	.8, ipch, 10
aout	<span class="opc">moogvcf</span>	aout, ipch <span class="op">+</span> (kenv <span class="op">*</span> 5 <span class="op">*</span> ipch) , .5

aout <span class="op">=</span> aout <span class="op">*</span> kenv

<span class="opc">outs</span> aout, aout
<span class="oblock">endin</span>
<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>

<span class="stamnt">i</span> 1 0 2 8.00 0
<span class="stamnt">i</span> 1 3 2 8.00 1
<span class="stamnt">i</span> 1 6 2 8.00 2
<span class="stamnt">e</span>
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
      </div>
      <div class="refsect1">
        <a id="idp100797536"></a>
        <h2>See Also</h2>
        <p>
      <a class="link" href="else.html" title="else"><em class="citetitle">else</em></a>,
      <a class="link" href="endif.html" title="endif"><em class="citetitle">endif</em></a>,
      <a class="link" href="goto.html" title="goto"><em class="citetitle">goto</em></a>,
      <a class="link" href="if.html" title="if"><em class="citetitle">if</em></a>,
      <a class="link" href="igoto.html" title="igoto"><em class="citetitle">igoto</em></a>,
      <a class="link" href="kgoto.html" title="kgoto"><em class="citetitle">kgoto</em></a>,
      <a class="link" href="tigoto.html" title="tigoto"><em class="citetitle">tigoto</em></a>,
      <a class="link" href="timout.html" title="timout"><em class="citetitle">timout</em></a>
    </p>
        <p> More information on this opcode: <a class="ulink" href="http://www.csoundjournal.com/2006spring/controlFlow.html" target="_top"><em class="citetitle">http://www.csoundjournal.com/2006spring/controlFlow.html</em></a>  , written by Steven Yi </p>
      </div>
      <div class="refsect1">
        <a id="idp100807632"></a>
        <h2>Credits</h2>
        <p>New in version 4.21</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="else.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="endif.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">else </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> endif</td>
        </tr>
      </table>
    </div>
  </body>
</html>
